<template>
	<view class="diamond-page">
		<z-paging ref="paging" v-model="dataList" @query="queryList">
			<!-- #ifdef APP -->
			<view slot="top">
				<u-navbar title="谁看过我" :autoBack="true" bgColor="transparent" :placeholder="true">></u-navbar>
			</view>
			<!-- #endif -->
			<view class="user-grid">
				<view class="user-card" v-for="(item, index) in dataList" :key="index" @click="lookUserDetail2(item)">
					<image :class="userInfo.vip?'blur-image':'blur-image filter8' " :src="item.user.avatar"
						v-if="userInfo.gender==1" mode="aspectFill">
					</image>
					<image :class="userInfo.is_auth==1?'blur-image':'blur-image filter8' " :src="item.user.avatar"
						v-if="userInfo.gender==2" mode="aspectFill">
					</image>
					<view class="user-box">
						<view class="real-user" v-if="item.user.is_auth==1">
							<image class="real-icon" mode="widthFix" src="../../static/common/real_user.png"></image>
						</view>
						<view class="user-info">
							<text class="name">{{ item.user.nickname }}</text>
						</view>
						<view class="user-detail">
							<text>{{ item.user.age }}岁 | {{ item.user.city }}</text>
							<text class="divider" v-if="item.user.distance">|</text>
							<text class="distance" v-if="item.user.distance">{{ item.user.distance }}km</text>
						</view>
						<image class="chat-icon" src="../../static/common/icon_chat.png"></image>
					</view>
				</view>
			</view>
		</z-paging>
		<userPopup :show="showUser" @close="showUser=false" :user_id="userDetail&&userDetail.id">
		</userPopup>
		<vipPopup :show="showVip" @close="showVip=false" @success="vipRechageSuccess"></vipPopup>
	</view>
</template>

<script>
	import userPopup from '@/components/UserPopup.vue';
	import vipPopup from '@/components/VipPopup.vue';
	export default {
		data() {
			return {
				dataList: [],
				userInfo: null,
				showUser: false,
				userDetail: null,
				showVip: false,
			}
		},
		components: {
			vipPopup: vipPopup,
			userPopup: userPopup,
		},
		onShow() {
			this.getUserInfo()
		},
		onBackPress() {
			if (this.showUser) {
				this.showUser = false
			}
		},
		methods: {
			//vip充值成功
			vipRechageSuccess() {
				this.showVip = false
				this.getUserInfo()
			},
			lookUserDetail2(item) {
				this.userDetail = item.user
				if (this.userInfo.gender == 1) {
					if (!this.userInfo.vip) {
						this.showVip = true
					} else {
						this.showUser = true
					}
				} else {
					if (this.userInfo.is_auth != 1) {
						this.$Tips('/pages/authentication/authentication')
					} else {
						this.showUser = true
					}
				}
			},
			getUserInfo() {
				this.$Api['user'].getUserInfo().then(res => {
					this.userInfo = res.data
				})
			},
			refreshList() {
				this.dataList = []
				this.$refs.paging.scrollToTop()
				this.$refs.paging.refresh();
			},
			queryList(pageNo, pageSize) {
				this.$Api['user'].getViewList({
					page: pageNo,
					limit: pageSize,
				}).then(res => {
					this.$refs.paging.complete(res.data.data);
				}).catch(res => {
					this.$refs.paging.complete(false);
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.diamond-page {
		width: 100%;
		min-height: 100vh;
		background-color: #ffffff;
		position: relative;

		.user-grid {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			gap: 20rpx;
			padding: 30rpx;
		}

		.user-card {
			width: 336rpx;
			height: 356rpx;
			background-color: #fff;
			border-radius: 12rpx;
			position: relative;
			background-size: 100% 100%;
			color: #ffffff;

			.blur-image {
				position: absolute;
				z-index: 10;
				width: 100%;
				height: 336rpx;
				border-radius: 14rpx;
			}

			.filter4 {
				filter: blur(4rpx);
			}

			.filter8 {
				filter: blur(8rpx);
			}

			.user-box {
				width: 100%;
				height: 100%;
				position: relative;
				z-index: 10;

				.real-user {
					position: absolute;
					left: 0;
					top: -20rpx;
					width: 138rpx;
					height: 50rpx;
					background: #F169F6;
					border-radius: 12rpx;
					z-index: 10;
					display: flex;
					align-items: center;
					justify-content: center;

					.real-icon {
						width: 100rpx;
					}
				}
			}



			.chat-icon {
				position: absolute;
				right: 20rpx;
				bottom: 52rpx;
				width: 44rpx;
				height: 44rpx;
				z-index: 10;
			}

			.user-info {
				padding: 220rpx 20rpx 10rpx;
				display: flex;
				align-items: center;

				.name {
					font-size: 16px;
					font-weight: bold;
				}
			}

			.user-detail {
				padding: 0 20rpx 20rpx;
				display: flex;
				align-items: center;
				font-size: 12px;

				.divider {
					margin: 0 10rpx;
				}

				.distance {
					color: #F169F6;
					margin-bottom: 10rpx;
				}
			}

			.user-photos {
				display: flex;
				padding: 0 20rpx 20rpx;

				.photo-item {
					width: 80rpx;
					height: 80rpx;
					margin-right: 10rpx;
					background-color: #f0f0f0;
					border-radius: 8rpx;

				}
			}
		}
	}
</style>